<template>
  <div>
    <el-cascader
      :value="value"
      separator="|"
      :options="options"
      :props="defaultProp"
      @change="hChange"
    />
  </div>
</template>

<script>
import { getDepartment } from '@/api/department'
import { arr2tree } from '@/utils'
export default {
  props: {
    value: {
      type: Number, // 存储的是部门的id  3 4 5

      //   default: 0
      required: true
    }
  },
  data() {
    return {
      defaultProp: {
        value: 'id',
        label: 'name'
      },
      options: []
    }
  },
  created() {
    this.loadDepartment()
  },
  methods: {
    async loadDepartment() {
      const res = await getDepartment()
      const options = arr2tree(res.data, 0)
      this.options = options
      console.log(options)
    },
    hChange(value) {
      console.log(value)
      const id = value[value.length - 1]
      console.log(id)
      this.$emit('input', id)
    }
  }
}
</script>

<style>

</style>
